package com.siemens.scr.avt.ad.teng;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class DBHelper {
	private static String URL = "jdbc:db2://europa.cci.emory.edu:50000/testdb";
    private String USERNAME = "tcgauser";
    private String PASSWORD = "userdb4321";
    Connection db2connection;
    Properties property = new Properties();
    private static String DRIVER_NAME = "com.ibm.db2.jcc.DB2Driver";
    
    public DBHelper()
    {
    	try {
		Class.forName(DRIVER_NAME).newInstance();
	    } catch (InstantiationException | IllegalAccessException
			| ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	property.put("user",USERNAME);
	property.put("password", PASSWORD);
	try {
		db2connection = DriverManager.getConnection(URL, property);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
		
	
    }
    
    public PreparedStatement getPstmt(String sql)
    {
    	try {
    		return db2connection.prepareStatement(sql);
    	} catch (SQLException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	}
    	return null;
    }
    
    
    
    public static void main(String[] args)
    {
    	DBHelper db = new DBHelper();
    	PreparedStatement ps = db.getPstmt("select FULL_HEADER from ad.general_image fetch 10");
    	
    	try {
    		
        	ResultSet rs = ps.executeQuery();
			while(rs.next()){
				System.out.println(rs.getString(1));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	
    }
    

}
